import * as homepageApi from '@/api/homepage';

export default {
  namespaced: true,
  state() {
    return {
      headerList: {},
      bannerList: {},
      freshList: {},
      popularList: {},
      brandList: {},
      goodsList: {},
      newgoodsList: {},
    };
  },
  mutations: {
    // 设置全部分类
    SET_HEADER(state, newValue) {
      state.headerList = newValue;
    },
    // 轮播图
    SET_BANNER(state, newValue) {
      state.bannerList = newValue;
    },
    // 新鲜好物
    SET_FRESH(state, newValue) {
      state.freshList = newValue;
    },
    // 人气推荐
    SET_POPULAR(state, newValue) {
      state.popularList = newValue;
    },
    // 热门品牌
    SET_BRAND(state, newValue) {
      state.brandList = newValue;
    },
    // 商品分类
    SET_GOODS(state, newValue) {
      state.goodsList = newValue;
    },
    // 最新推荐
    SET_NEWGOODS(state, newValue) {
      state.newgoodsList = newValue;
    },
  },
  actions: {
    // 设置全部分类
    async updateHeader({ commit }) {
      const res = await homepageApi.header();
      commit('SET_HEADER', res);
    },
    // 轮播图
    async updateBanner({ commit }) {
      const res = await homepageApi.banner();
      commit('SET_BANNER', res);
    },
    // 新鲜好物
    async updateFresh({ commit }) {
      const res = await homepageApi.fresh();
      commit('SET_FRESH', res);
    },
    // 人气推荐
    async updatePopular({ commit }) {
      const res = await homepageApi.popular();
      commit('SET_POPULAR', res);
    },
    // 热门品牌
    async updateBrand({ commit }) {
      const res = await homepageApi.brand();
      commit('SET_BRAND', res);
    },
    // 商品分类
    async updateGoods({ commit }) {
      const res = await homepageApi.goods();
      commit('SET_GOODS', res);
    },
    // 最新推荐
    async updateNewGoods({ commit }) {
      const res = await homepageApi.newgoods();
      commit('SET_NEWGOODS', res);
    },
  },
};
